package com.project.controller;

import com.project.bean.ManBean;
import com.project.service.IManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("man")
public class ManController {
    @Autowired
    private IManService service;

    @RequestMapping("findAll")
    public String findAll(HttpServletRequest request){
        //调用业务方法，得到数据
        List<ManBean> list =  service.findAll();
        //绑定共享数据
        request.setAttribute("list",list);
        return "/index.html";
    }

    @RequestMapping("add")
    public String add(ManBean man){
        service.add(man);
        return "redirect:/man/findAll";
    }

    @RequestMapping("del")
    public String del(Integer id){
        service.del(id);
        return "redirect:/man/findAll";
    }

    @RequestMapping("findById")
    public String findById(Integer id,HttpServletRequest request){
        ManBean man = service.findById(id);
        request.setAttribute("man",man);
        return "/update.html";
    }

    @RequestMapping("update")
    public String update(Integer id,String phone){
        service.update(id,phone);
        return "redirect:/man/findAll";
    }
}
